package rebol.eclipse.plugin.xml;

import java.awt.Point;
import java.beans.XMLEncoder;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.sql.Time;
import java.util.Date;

import rebol.eclipse.plugin.helpers.Config;
import rebol.eclipse.plugin.helpers.Rebol;
import rebol.eclipse.plugin.xml.rebol.EMail;
import rebol.eclipse.plugin.xml.rebol.GetWord;
import rebol.eclipse.plugin.xml.rebol.Issue;
import rebol.eclipse.plugin.xml.rebol.LitPath;
import rebol.eclipse.plugin.xml.rebol.LitWord;
import rebol.eclipse.plugin.xml.rebol.None;
import rebol.eclipse.plugin.xml.rebol.Paren;
import rebol.eclipse.plugin.xml.rebol.Path;
import rebol.eclipse.plugin.xml.rebol.RFile;
import rebol.eclipse.plugin.xml.rebol.RString;
import rebol.eclipse.plugin.xml.rebol.RTag;
import rebol.eclipse.plugin.xml.rebol.RTime;
import rebol.eclipse.plugin.xml.rebol.RURL;
import rebol.eclipse.plugin.xml.rebol.Refinement;
import rebol.eclipse.plugin.xml.rebol.SetPath;
import rebol.eclipse.plugin.xml.rebol.SetWord;
import rebol.eclipse.plugin.xml.rebol.Tuple;
import rebol.eclipse.plugin.xml.rebol.Word;

public class SaveBeanTemplates {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		//String wordConv = " bean-tag/b (target/void/b/string/b/1: form val ) to-reb [get-bean-name val]";
		//String stringConv = " bean-tag/b (set-bean-string target form val ) to-reb [get-bean-string val]";
		String stringConv1 = " bean-tag/b (set-bean-string target form val ) to-reb [";
		String stringConv2 =" get-bean-string val]";
		String seriesConv1 = " bean-tag/b/void/b/array (insert clear target to-bean-array val) to-reb [";
		String seriesConv2 = " new-line/all beans-to-rebol val false]";
		Object[] o = new Object[] { 
				//rebol-type base-path to-bean 'to-reb to-rebol
"tuple! bean-tag/b/void/b/array (insert clear target to-bean-tuple load replace/all mold val \".\" \" \") to-reb [to-tuple probe beans-to-rebol ?? val]",new Tuple(new byte[]{1,2}),
"byte! bean-tag/b/1 [make error! \"no bytes in rebol\"]", (byte)0, 
				"word! bean-tag/b/1 [mold val]", "a Word",
				"integer! bean-tag/b/1 [mold val]", 0, 
				"decimal! bean-tag/b/1 [mold val]", 0.0,
				"string!" + stringConv1 + stringConv2, new RString("a String"),
				"pair! bean-tag/b (target/3/b/1: mold val/x . target/6/b/1: mold val/y) to-reb [val: by-mark val 'int . as-pair to-integer val/1/b/1 to-integer val/2/b/1]", new Point(1,2),
				"block! bean-tag (head insert clear target to-bean-array val) to-reb [beans-to-rebol val]",new Object[]{1},
				"word!" + stringConv1 + "to-word" + stringConv2, new Word("a Word"), //Dupe, usually string
				"get-word!" + stringConv1 + "to-get-word" + stringConv2, new GetWord("a Word"),
				"set-word!" + stringConv1 + "to-set-word" + stringConv2, new SetWord("a Word"),
				"lit-word!" + stringConv1 + "to-lit-word" + stringConv2, new LitWord("a Word"),
				"refinement!" + stringConv1 + "to-refinement" + stringConv2, new Refinement("a Word"),
				//more strings
				"url!" + stringConv1 + "to-url" + stringConv2, new RURL("a String"),
				"file!" + stringConv1 + "to-file" + stringConv2, new RFile("a String"),
				"issue!" + stringConv1 + "to-issue" + stringConv2, new Issue("a String"),
				"tag!" + stringConv1 + "to-tag" + stringConv2, new RTag("a String"),
				"email!" + stringConv1 + "to-email" + stringConv2, new EMail("a String"),
				//none tricky. null is not stored on the java-side
				"none! bean-tag () to-reb[none]", new None(),
				"char! bean-tag/b/1 [to-string val]",'c',
				"logic! bean-tag/b/1 [mold val] to-reb[get first find[true false] to-word val]",true,
				"paren!" + seriesConv1 + "to-paren" + seriesConv2,new Paren(new Object[]{"empty"}),
				"path!" + seriesConv1 + "to-path" + seriesConv2,new Path(new Object[]{"empty"}),
				"set-path!" + seriesConv1 + "to-set-path" + seriesConv2,new SetPath(new Object[]{"empty"}),
				"lit-path!" + seriesConv1 + "to-lit-path" + seriesConv2,new LitPath(new Object[]{"empty"}),
				"time!" + stringConv1 + "to-time" + stringConv2, new RTime(new Time(1000)),
				"date! bean-tag/b/long/b/1 (to-bean-date target val) to-reb [to-reb-date val]", new Date(),
				
		};

		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		XMLEncoder xe = new XMLEncoder(bos);
		xe.writeObject(o);
		xe.close();

		String inp = bos.toString();
		Rebol.printConfig();
		Rebol.call(new File(Config.scriptDir,
				"save-bean-templates.r"), "", inp, true);
		
		//
		Rebol.testXMLCall();

	}

}
